package lambdademo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @Author 12629 
 * @Description：
 */









//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}

//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}


//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

public class Test {

    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "abc");
        map.put(4, "lambda");

        /*map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key: "+integer +" val: "+s);
            }
        });*/

        map.forEach((k,v)->System.out.println("key: "+k +" val: "+v));
    }

    public static void main5(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("bit");
        list.add("abc");
        list.add("lambda");

        /*list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/

        list.forEach(s-> System.out.println(s));

       /* list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/

        list.sort((x,y)->x.compareTo(y));

        System.out.println("======");

        list.forEach(s-> System.out.println(s));
    }

    public static void main4(String[] args) {


        int a = 99;
        NoParameterNoReturn noParameterNoReturn = ()->{
            //a = 88;
            System.out.println(a);
            System.out.println("hello");
        };


    }

    public static void main3(String[] args) {
        //NoParameterReturn noParameterReturn = ()->{return 10;};
        NoParameterReturn noParameterReturn = ()->10;
        System.out.println(noParameterReturn.test());

        System.out.println("=========");
        OneParameterReturn oneParameterReturn = x -> x*2;
        System.out.println(oneParameterReturn.test(9));
        System.out.println("=========");
        MoreParameterReturn moreParameterReturn = (x,y) -> x*y;
        System.out.println(moreParameterReturn.test(9,9));

    }


    public static void main2(String[] args) {
        NoParameterNoReturn noParameterNoReturn = ()->{System.out.println("hello");};

        //OneParameterNoReturn oneParameterNoReturn = (int a)->{System.out.println(a);};
        OneParameterNoReturn oneParameterNoReturn = a->System.out.println(a);
        oneParameterNoReturn.test(10);

        MoreParameterNoReturn moreParameterNoReturn = ( a, b) -> System.out.println(a+b);

        moreParameterNoReturn.test(1,2);
    }



    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("hello");
            }
        };

        noParameterNoReturn.test();


        int a = 10;

        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //a = 99;
                System.out.println(a);
                return o1.compareTo(o2);
            }
        });


        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>((x,y) -> x.compareTo(y));



    }
}
